#include<stdio.h>
#include<unistd.h>
int main(int argc,char *argv[])
{
	int cfd1,cfd2;
	char str1[]="Hi~\n";
	char str2[]="It's nice day~\n";
	//复制文件描述符
	//int dup(int fildes)
	//int dup2(int fildes,int fildes2)
	cfd1=dup(1);
	cfd2=dup2(cfd1,7);
	
	printf("fd1=%d,fd2=%d\n",cfd1,cfd2);
	write(cfd1,str1,sizeof(str1));
	write(cfd2,str2,sizeof(str2));
	
	close(cfd1);
	close(cfd2);
	write(1,str1,sizeof(str1));
	close(1);
	write(1,str2,sizeof(str2));//所有文件描述符都关闭，此时无法输出
	return 0;
}
